package com.cqc.jdk8.Jlang;

import org.junit.Test;

public class StringTest {
    /**
     * replaceAll(String regex, String replacement) 匹配正则后替换 或者 替换普通字符串
     * replace(CharSequence target, CharSequence replacement) 替换字符串
     * 二者在替换普通字符串时没有区别，但是在替换 需要转义的字符时，replaceAll必须加转义字符\\
     */
    @Test
    public void f1() {
        String a = "abadafg";
        System.out.println("result=" + a.replaceAll("a","A"));
        System.out.println("result=" + a.replace("a","A"));

        //2025-10-01
        System.out.println("2025-10-01".replace("[^0-9]",""));
        //20251001
        System.out.println("2025-10-01".replaceAll("[^0-9]",""));
        //abc
        System.out.println("a.b.c".replace(".",""));
        //空
        System.out.println("a.b.c".replaceAll(".",""));
        //abc
        System.out.println("a.b.c".replaceAll("\\.",""));
    }
    @Test
    public void f2() {
        String a = "0005";
        String result = String.format("%011d", 1 + Integer.parseInt(a));
        System.out.println("result=" + result);
    }

    @Test
    public void f7() {
        String a = "he";
        String b = "llo";
        String c = ",";
        String d = "java";
        String concat = a.concat(b).concat(c).concat(d);
        //hello,java
        System.out.println(concat);
    }
}
